package com.core.reach.cloudhub.controller;

import com.core.reach.cloudhub.domain.CommonResult;
import com.core.reach.cloudhub.service.AccountService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @author ga.zhang
 * @version V1.0
 * @description: TODO
 * @date 2020/4/1 16:09
 **/
@RestController
public class AccountController {

    @Resource
    private AccountService accountService;

    @PostMapping("/account/decrease")
    public CommonResult decrease(@RequestParam("userId") Long userId, @RequestParam("money") BigDecimal money) {
        Boolean reduceAccount = accountService.reduceAccount(userId, money);
        if (reduceAccount) {
            return new CommonResult(200, "扣减余额成功", Boolean.TRUE);
        } else {
            return new CommonResult(444, "扣减余额失败", Boolean.FALSE);
        }
    }

}
